import path from 'path';

function resolve(name) {
  return path.resolve(__dirname, '..', name);
}

const config = {
  projectName: 'aunt-job-app-v3',
  date: '2021-12-19',
  designWidth: 375,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2,
    375: 2 / 1,
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  plugins: [
    '@tarojs/plugin-html',
    'taro-plugin-pinia',
    [
      '@tarojs/plugin-framework-vue3',
      {
        mini: {
          compilerOptions: {
            isCustomElement: (tag) => tag.includes('van-'),
            whitespace: 'preserve',
          },
        },
      },
    ],
  ],
  defineConstants: {},
  copy: {
    patterns: [{
        from: 'src/vant-weapp/wxs',
        to: 'dist/vant-weapp/wxs',
      },
      {
        from: 'src/vant-weapp/common',
        to: 'dist/vant-weapp/common',
      },
      {
        from: 'src/vant-weapp/dropdown-menu',
        to: 'dist/vant-weapp/dropdown-menu',
      },
      {
        from: 'src/vant-weapp/dropdown-item',
        to: 'dist/vant-weapp/dropdown-item',
      },
      {
        from: 'src/vant-weapp/popup',
        to: 'dist/vant-weapp/popup',
      },
      {
        from: 'src/vant-weapp/mixins',
        to: 'dist/vant-weapp/mixins',
      },
      {
        from: 'src/vant-weapp/cell',
        to: 'dist/vant-weapp/cell',
      },
      {
        from: 'src/vant-weapp/cell-group',
        to: 'dist/vant-weapp/cell-group',
      },
      {
        from: 'src/vant-weapp/icon',
        to: 'dist/vant-weapp/icon',
      },
      {
        from: 'src/vant-weapp/info',
        to: 'dist/vant-weapp/info',
      },
      {
        from: 'src/vant-weapp/overlay',
        to: 'dist/vant-weapp/overlay',
      },
      {
        from: 'src/vant-weapp/transition',
        to: 'dist/vant-weapp/transition',
      },
      {
        from: 'src/vant-weapp/empty',
        to: 'dist/vant-weapp/empty',
      },
      {
        from: 'src/vant-weapp/button',
        to: 'dist/vant-weapp/button',
      },
      {
        from: 'src/vant-weapp/loading',
        to: 'dist/vant-weapp/loading',
      },
      {
        from: 'src/vant-weapp/divider',
        to: 'dist/vant-weapp/divider',
      },
      {
        from: 'src/vant-weapp/search',
        to: 'dist/vant-weapp/search',
      },
      {
        from: 'src/vant-weapp/field',
        to: 'dist/vant-weapp/field',
      },
      {
        from: 'src/vant-weapp/tag',
        to: 'dist/vant-weapp/tag',
      },
      {
        from: 'src/vant-weapp/grid',
        to: 'dist/vant-weapp/grid',
      },
      {
        from: 'src/vant-weapp/grid-item',
        to: 'dist/vant-weapp/grid-item',
      },
      {
        from: 'src/vant-weapp/swipe-cell',
        to: 'dist/vant-weapp/swipe-cell',
      },
    ],
    options: {},
  },
  framework: 'vue3',
  alias: {
    '@': resolve('src'),
  },
  mini: {
    postcss: {
      pxtransform: {
        enable: true,
        config: {
          selectorBlackList: [/van-/],
        },
      },
      url: {
        enable: true,
        config: {
          limit: 1024, // 设定转换尺寸上限
        },
      },
      cssModules: {
        enable: true, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]',
        },
      },
    },
    // addChunkPages(pages) {
    //   pages.set('subpackages/avatar/index', ['subpackages/common']);
    //   pages.set('subpackages/pofile/index', ['subpackages/common']);
    // },
    // webpackChain(chain) {
    //   chain.merge({
    //     optimization: {
    //       splitChunks: {
    //         cacheGroups: {
    //           subpackagesCommon: {
    //             name: 'subpackages/common',
    //             minChunks: 2,
    //             test: (module, chunks) => {
    //               const isNoOnlySubpackRequired = chunks.find(
    //                 (chunk) => !/\bsubpackages\b/.test(chunk.name)
    //               );
    //               return !isNoOnlySubpackRequired;
    //             },
    //             priority: 200,
    //           },
    //         },
    //       },
    //     },
    //   });
    // },
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    postcss: {
      autoprefixer: {
        enable: true,
        config: {},
      },

      cssModules: {
        enable: true, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]',
        },
      },
    },
  },
};

module.exports = function (merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'));
  }
  return merge({}, config, require('./prod'));
};
